package com.uinnova.product.eam.init.schedule;

import com.binary.framework.bean.annotation.Comment;
import com.uinnova.product.eam.init.schedule.job.CmdbDataSyncJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Comment("cmdb数据同步定时任务配置")
@Configuration
public class CmdbDataSyncConfiguration {

    @Value("${guotou.cmdb.data.sync.cron:0 0/5 * * * ?}")
    private String cmdbDataSyncCron;

    @Bean
    public JobDetail cmdbSyncJob() {
        return JobBuilder.newJob(CmdbDataSyncJob.class).withIdentity("CmdbDataSyncJob").storeDurably().build();
    }

    @Bean
    public Trigger cmdbSyncJobTrigger(JobDetail cmdbSyncJob) {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cmdbDataSyncCron);
        return TriggerBuilder.newTrigger().forJob(cmdbSyncJob)
                .withIdentity("CmdbDataSyncJob").withSchedule(scheduleBuilder).build();
    }

}